
//$attachmentList = $('#attachmentList');
var PATH_PREFIX ="";

var ARCHIVE_PATH = "";

var noDataBoxStr = "<div class='data-box'>"+
	"<img src='"+contextPath+"/resources/modules/bootstrap/image/nodata.jpg'>"+
	"<span class='no-data'>当前无数据</span>"+
	"</div>";

function setPathPrefix(path,archivePath){
	PATH_PREFIX =  path;
	ARCHIVE_PATH = archivePath;
}
$(function() {
	debugger;
	var operationMode = $('#operationMode').val();
	if(operationMode == 1){
		$('#openFrequency').show();
	}
	
	isShowPicture();
//	$('header').hide();
	
	//lineChart();
	
	var element = $('.font-color-white.time');
	var val = $(element).attr('frequency');
	console.log(val);
	navData(val);
	
	// 费用空给默认格式
	$('.span-yellow-20').each(function(index,element){
		if($(element).html() == null || $.trim($(element).html()) == '' || $.trim($(element).html()) == '%'  ){
			$(element).html('--');
		}
    });
	
	
	
});

function chooseTime(elem){
	$('.time').each(function(index,element){
		$(element).removeClass('font-color-white');
	});
	$(elem).addClass('font-color-white');
	var val = $(elem).attr('frequency');
	console.log(val);
	navData(val);
}


function navData(limit) {
	debugger;
	var subPrdCode = $('#prdCode').val();
	$.ajax({
		type : "POST",
		dataType : "json",
		url : PATH_PREFIX + "navData.do",
		cache: false,
		data: {
			'subPrdCode': subPrdCode,
			'limit':limit
		},
		success: function(data) {
			if (data.success) {
				var navData = data.object;
				//console.log(navData);
				lineChart(navData);
				
			} else {
				lineChart('');
			}
		},
		error:function(xhr){
		   sweetAlertAjaxError(xhr);
		}
	});
}

// 是否显示折线图
function isShowPicture(){
	var prdType = $('#prdType').val();
	if(prdType != 'FIXED_INCOMDE'){
		$('#picture').show();
	}
}

function queryByCondtion(flag) {
	//产品代码
	var prdCode = $.trim($("#prdCode").val());
	console.log("prdCode:"+prdCode);
    var postData = $attachmentList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
        'sp[prdCode]':prdCode
    });
    if (flag) {
    	$attachmentList.trigger("reloadGrid", [{ page: 1 }]); //重新载入Grid表格
    } else {
    	$attachmentList.trigger("reloadGrid"); //重新载入Grid表格
    }
}


//历史单位净值折线图
function lineChart(navData) {
  //var data = [{"估值日":"2019-01-08","单位净值":"1.0263","组合":"1.0025"},{"估值日":"2019-01-09","单位净值":"1.0367","组合":"1.0032"},{"估值日":"2019-01-10","单位净值":"1.0347","组合":"1.0038"},{"估值日":"2019-01-11","单位净值":"1.0422","组合":"1.0045"},{"估值日":"2019-01-14","单位净值":"1.0331","组合":"1.0047"},{"估值日":"2019-01-15","单位净值":"1.0534","组合":"1.0053"},{"估值日":"2019-01-16","单位净值":"1.0536","组合":"1.0053"},{"估值日":"2019-01-17","单位净值":"1.0478","组合":"1.0055"},{"估值日":"2019-01-18","单位净值":"1.0669","组合":"1.0059"},{"估值日":"2019-01-21","单位净值":"1.0728","组合":"1.0059"},{"估值日":"2019-01-22","单位净值":"1.0585","组合":"1.0066"}];
	debugger;
	console.log(navData);
  
	var data = '';
	if(navData && navData.length > 1){
		data = navData;
		 $("#timeZone").show();
	}
  
  /*if(navData != null && $.trim(JSON.parse(navData)) != '' && JSON.parse(navData).length > 1){
	  data = JSON.parse(navData);
  }*/

  if (data.length > 0) {
    var lines = [];
    var arr1 = [];
    $.each(data, function() {
      var obj = {};
      obj.name = new Date(this['估值日']).toString();
      obj.value = [this['估值日'], this['单位净值']];
      arr1.push(obj);
    });
    
    /*var name1 = '组合';*/
    var name2 = '单位净值';
    /*lines.push({
      'name' : name1,
      'type' : 'line',
      'showSymbol' : false,
      'symbol': 'none',
      'hoverAnimation' : false,
      'areaStyle': {},
      'data' : arr2
    });*/
    
    lines.push({
      'name' : name2,
      'type' : 'line',
      'showSymbol' : false,
      'symbol': 'none',
      'hoverAnimation' : false,
     /* 'areaStyle': {},*/
      'data' : arr1
    });

    var myChart = echarts.init(document.getElementById('_2'));
    var option = $.extend(echartsTheme, {
      tooltip : {
        trigger : 'axis',
        axisPointer : {
          animation : false
        }
      },
     /* legend : {
        data : [name2],
        left : '10px'
//        left: '60px',
//        top: '10px'
      },*/
      grid : {
        bottom : '40px',
        left : '60px',
        right: '40px',
        top : '40px'
      },
      xAxis : {
        type : 'category',
        splitLine: {
          lineStyle: {
            type: 'dashed'
          }
        },
        axisLine: {
          show: false
        },
        axisTick: {
          show: false
        }
      },
      yAxis : {
    	name: '净值',
        type : 'value',
        boundaryGap : [ 0, '100%' ],
        min : function(value) {
          return (value.min * 10000 * 98 / 1000000).toFixed(4);
        },
        max : function(value) {
          return (value.max * 10000 * 102 / 1000000).toFixed(4);
        },
        axisLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        splitLine: {
          lineStyle: {
            type: 'dashed'
          }
        },
        axisLabel: {
            formatter: function (value, index) {
            	value = value.toFixed(2);
                return value;
            }
        }
      },
      series : lines
    });
    myChart.clear();
    myChart.setOption(option);
  }else{
	  debugger;
	  $("#_2").empty();
	  $("#_2").append(noDataBoxStr);
	 
  }
}

/**
 * 保存文档信息
 */
function submitForm() {
	SubmitAndPreventSecond("estimateForm",function(){
		debugger;
		//获取附件ID
		$('#attIds').val(serialAttId("attachContainerinvest"));
		
		var url = PATH_PREFIX + "saveAttaches.do";
		$("#estimateForm").attr("action",url);
	});
}





